package com.bw.controller;

import com.bw.domain.TbMenu;
import com.bw.domain.User;
import com.bw.service.MenuService;
import com.bw.utils.MenuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author bobo棒
 * @date 2025年02月21日 15:33
 */

@Controller
public class MainController {
    @Autowired
    MenuService menuService;

    /**
     * 进入系统主页,并显示对应菜单
     * @param session
     * @return
     */
    @RequestMapping("main")
    public String main(HttpSession session, Model model){
        User user = (User) session.getAttribute("user");
        //根据当前登录人的信息查询其拥有的菜单
        List<TbMenu> menuList= menuService.list(user.getId());
       //转成树形结构
        List<TbMenu> list = MenuUtil.treeMenus(menuList, null);

        model.addAttribute("list",list);

        return "main";
    }
}
